package com.medical_houduan.controller;

import com.medical_houduan.commons.Result;
import com.medical_houduan.dto.SaleDto;
import com.medical_houduan.service.SaleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sale")
@Tag(name = "销售地点接口",description = "这个接口用于销售地点")
public class SaleController {
    @Autowired
    SaleService saleService;

    @GetMapping("/getSale")
    @Operation(summary = "获取销售地点数据",description = "获取数据库所有的销售地点，关键字可选")
    public Result getSales(@RequestParam(value = "currentPage",defaultValue = "1",required = false) Integer currentPage,
                               @RequestParam(value = "pageSize",defaultValue = "10",required = false) Integer pageSize,
                               @RequestParam(value = "key",required = false) String keyword){
        return saleService.getSales(currentPage,pageSize,keyword);
    }

    @GetMapping("/{sid}")
    @Operation(summary = "查询指定的销售地点数据",description = "查询指定的销售地点数据，传入SaleDto对象,RestFull风格")
    public Result findSale(@PathVariable("sid") Long saleId){
        return saleService.getSaleById((saleId));
    }

    @PostMapping("/updateSale")
    @Operation(summary = "修改销售地点数据",description = "修改销售地点数据，传入SaleDto对象")
    public Result updateSale(@RequestBody SaleDto saleDto){
        return saleService.updateSale(saleDto);
    }

    @PostMapping("/addSale")
    @Operation(summary = "添加销售地点数据",description = "添加销售地点数据，传入SaleDto对象")
    public Result addSale(@RequestBody SaleDto saleDto){
        return saleService.addSale(saleDto);
    }

    @GetMapping("/deleteSale/{sid}")
    @Operation(summary = "删除销售地点数据",description = "删除指定的销售地点数据，传入SaleDto对象,RestFull风格")
    public Result deleteSale(@PathVariable("sid") Long saleId){
        return saleService.deleteSale(saleId);
    }
}
